package com.example.demomk.Dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Transaction;
import androidx.room.Update;

import com.example.demomk.entity.Measurement;

import java.util.List;

@Dao
public interface MeasurementDao {
    @Insert
    long insertMeasurement(Measurement measurement);

    @Update
    void updateMeasurement(Measurement measurement);

    @Delete
    void deleteMeasurement(Measurement measurement);
    @Query("DELETE FROM measurements")
    void deleteAllMeasurements();




    // 统计查询
    @Query("SELECT COUNT(*) FROM measurements")
    LiveData<Integer> getMeasurementCount();


    @Query("SELECT * FROM measurements WHERE parent_id = :id")
    List<Measurement> getMeasurementsByUserId(int id);

    // 查询所有记录（用于常规视图）
//    @Query("SELECT m.id, m.start_time, l.group_name , l.location_name as location, u.user_name as user " +
//            "FROM measurements m " +
//            "JOIN users u ON m.user_id = u.id " +
//            "JOIN locations l ON m.location_id = l.id " +
//            "ORDER BY m.id DESC")
//    LiveData<List<MeasurementSummary>> getAllSummaries();
}
